package com.example.ai.model.source

import com.example.ai.model.api.Api
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * Created by lijinxi on 2024/3/11.
 * @Description:
 */
class HttpSource {
    companion object {
        const val BASE_URL = "https://workspace-wsbb56b05d5f82b404-http-8888.ide.byted.org"
        const val PIC_URL =
            "https://raw.githubusercontent.com/YourBroDuke/personal_os/main/20240308-155429.jpeg"
    }

    private fun <T> create(serviceClass: Class<T>): T {
        return Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
            .create(serviceClass)
    }

    private val api: Api = create(Api::class.java)

    suspend fun fetchVoice(text: String, speaker: String = "zh_male_taiwan") =
        api.getVoice(text, speaker)

    suspend fun fetchTalkID(audioUrl: String, picUrl: String = PIC_URL) =
        api.generateTalk(audioUrl, picUrl)

    suspend fun fetchTalkUrl(talkID: String) = api.getTalk(talkID)
}